<?php

class People_FloorController extends Base_Controller_Action
{
    public function manageAction()
    {
        $group = new Model_Group();
        try {
            $group->read($this->_getParam('aid'));
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage(404);
        }
        
        //question list
        $dbTable = new Table_Floor();
        $where = array("`people_floor`.`vid` = '".$group->vid."' AND `people_floor`.`gid` = '".$group->gid."'");
        $this->view->group = $group;
        $this->view->village = $group->getVillage();
        $this->view->street = $this->view->village->getStreet();
        $this->view->entries = $dbTable->view($where, 'number ASC');

    }
    
    public function createAction()
    {
        //create form
        $this->form = new Form_Floor_Create();
        
        try {
            $this->create('floor');
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
        
        $group = new Model_Group();
        try {
            $group->read($this->_getParam('aid'));
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
        
        //check oid
        $this->form->gid->setValue($group->gid);
        $this->form->vid->setValue($group->getVillage()->vid);
    }
    
    public function modifyAction()
    {
        //create form
        $this->form = new Form_Floor_Modify();
        
        try {
            $this->modify('floor');
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
    
    public function deleteAction()
    {
        $this->form = new Form_Floor_Delete();
        
        //drop post
        try {
            $this->delete('floor');
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
}